<?php

use Biz\model\activity\SNJActivityRecord;
use Doraemon\service\Member;

/**
 * @deprecated
 * 三棱镜 广告活动记录
 * Class SNJRecordAction
 */
class GetJoinSNJUserAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $data = [];
        $info = SNJActivityRecord::getRecordListByCondition([
            'AND' => ['type' => SNJActivityRecord::NORMAL_TYPE],
            'ORDER' => ['addtime' => 'DESC'],
            'LIMIT' => 20
            ]);
        if($info && is_array($info)){
           $uids = array_column($info , 'uid');
           $memberInfos =   Member::getUserInfoByUserIds($uids);
           foreach ($uids as $uid){
                if(empty($memberInfos[$uid])) continue;
                $data[] = [
                    'uid' => $uid,
                    'avatar' => $memberInfos[$uid]['avatar_small'],
                    'nick' => $memberInfos[$uid]['nick']
                ];
           }
           if(count($data) < 20){
              $fakeInfo =  $this->getFakeUser( 20 - count($data));
              $data =  array_merge($data , $fakeInfo);
           }
        }
        $this->setSuccess($data);
    }


    public function getFakeUser($limit)
    {
        $fakeInfo = [];
        $fakeUids  =[9412678,9696346,3589600,9487344,7726059,7360089,12919708,2362056,10486758,9412678,10493398,73282528,10230887,3477816,10746180,12945966,11747973,12945973,6846376,9286263];
        shuffle($fakeUids);
        $uids = array_slice($fakeUids , 0,$limit);
        $memberInfos =   Member::getUserInfoByUserIds($uids);
        foreach ($uids as $uid){
            if(empty($memberInfos[$uid])) continue;
            $fakeInfo[] = [
                'uid' => $uid,
                'avatar' => $memberInfos[$uid]['avatar_small'],
                'nick' => $memberInfos[$uid]['nick']
            ];
        }
       return  $fakeInfo;
    }
}